<template>
  <div class="spaceUsageAnalyze">
    <a-flex gap="middle">
      <a-card title="存储空间" style="width: 50%">
        <div style="height: 320px; text-align: center">
          <h3>
            {{ formatBytes(data.usedSize) }}/{{
              data.maxSize ? formatBytes(data.maxSize) : '无限制'
            }}
          </h3>
          <a-progress type="dashboard" :percent="data.sizeUsageRatio ?? 0" />
        </div>
      </a-card>
      <a-card title="图片数量" style="width: 50%">
        <div style="height: 320px; text-align: center">
          <h3>{{ data.usedCount }}/{{ data.maxCount ? data.maxCount : '无限制' }}</h3>
          <a-progress type="dashboard" :percent="data.countUsageRatio ?? 0" />
        </div>
      </a-card>
    </a-flex>
  </div>
</template>
<script setup lang="ts">
import 'echarts'
import { ref, watchEffect } from 'vue'
import { message } from 'ant-design-vue'
import { getSpaceUsageAnalyzeUsingPost } from '@/api/spaceAnalyzeController'
import { formatBytes } from '@/utils'
interface Props {
  queryAll?: boolean
  spaceId?: number
  queryPublic: boolean
}
const props = withDefaults(defineProps<Props>(), { queryAll: false, queryPublic: false })

const loading = ref(true)

//图表数据

const data = ref<API.SpaceUsageAnalyzeResponse>({})
const fetchData = async () => {
  try {
    const res = await getSpaceUsageAnalyzeUsingPost({
      queryAll: props.queryAll,
      spaceId: props.spaceId,
      queryPublic: props.queryPublic,
    })
    if (res.data.code === 200 && res.data.data) {
      data.value = res.data.data
    } else {
      message.error('获取空间使用数据失败或' + res.data.message)
    }
  } catch (err) {
    message.error('获取空间使用数据失败' + err)
  }
}
//参数改变时，要改变a获取数据
watchEffect(() => {
  fetchData()
})
</script>